package rpc.init;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.net.InetAddress;
import java.net.UnknownHostException;

//@Component
@ConfigurationProperties(prefix = "xiaobaibai.rpc.center")
public class RpcConfig {

    //当前的端口
    private String port;

    public String getIp() {
        InetAddress address = null;
        try {
            address = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        assert address != null;
        return address.getHostAddress();
    }

    public Integer getPort() {
        if(this.port==null){
            throw new RuntimeException("请配置注册中心的端口号");
        }
        return Integer.parseInt(port);
    }

    public void setPort(String port) {
        this.port = port;
    }

}
